<template>
  <div class="header-box">
    <div class="left">
      <image
        @click="toDebug"
        mode="widthFix"
        class="title_text_img"
        :src="titleTextFff"
      />
    </div>
    <div
      class="right flex items-center font-size-18 font-weight-700 color-inverse"
    >
      <div
        :class="[
          'flex items-center m-l-20',
          websocketStore.onLine ? 'color-success' : '',
        ]"
      >
        <div
          :class="[
            'iconfont font-size-19 m-r-5',
            websocketStore.onLine ? 'icon-wifi' : 'icon-WIFIjinyong',
          ]"
        ></div>
        <div>{{ websocketStore.onLine ? "在线" : "离线" }}</div>
      </div>

      <div @click="lockDialogRef.switchShow()" class="flex items-center m-l-20">
        <div class="iconfont icon-mima font-size-18 m-r-5"></div>
        <div>锁屏</div>
      </div>
    </div>
  </div>

  <LockDialog ref="lockDialogRef" />
</template>
<script setup>
import { ref } from "vue";
import titleTextFff from "@/static/images/title_text_fff.png";
import { useWebSocketStore } from "../../store/websocket";
const websocketStore = useWebSocketStore();
import utils from "@/utils/index";

const lockDialogRef = ref()
const emit = defineEmits(["clickLock"]);

var clickCount = 0;
var lastClickTime = 0;
async function toDebug() {
  const now = Date.now();
  console.log("now", now);
  // 两次点击间隔小于800ms才算连续
  if (now - lastClickTime < 800) {
    clickCount++;
  } else {
    clickCount = 1;
  }
  lastClickTime = now;

  console.log(clickCount);

  if (clickCount === 10) {
    let curPages = getCurrentPages();
    // 如果当前页面是调试页面，则不跳转
    if (
      curPages.length > 0 &&
      curPages[curPages.length - 1].route === "pages/debug/debug"
    ) {
      return;
    }

    clickCount = 0; // 重置点击次数
    utils.toUrl("/pages/debug/debug");
  }
}
</script>
<style lang="scss" scoped>
.header-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18rpx;
  padding: 10rpx 20rpx;

  width: 100vw;
  height: 60px;
  opacity: 1;
  background: $uni-color-primary;
  box-shadow: 0px 0px 13.33px rgba(0, 0, 0, 0.1);

  .left {
    .title_text_img {
      width: 202px;
    }
    flex: 1;
    width: 0;
  }
}
</style>
